package com.ws.gold.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ws.gold.config.PageQuery;
import com.ws.gold.domain.WarehouseHoldSituation;
import com.ws.gold.service.WarehouseHoldSituationService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * @author ws
 * @create 2025/6/27
 */
@RestController
@RequestMapping("/warehouse-hold-situation")
@RequiredArgsConstructor
public class WarehouseHoldSituationController {

    private  final WarehouseHoldSituationService warehouseHoldSituationService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public WarehouseHoldSituation add(@RequestBody WarehouseHoldSituation warehouseHoldSituation) {
        return warehouseHoldSituationService.addNew(warehouseHoldSituation);
    }

    /**
     * 删除
     */
    @PostMapping("/deletes")
    public boolean delete(@RequestBody List<Long> ids) {
        return warehouseHoldSituationService.removeBatchByIds(ids);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public WarehouseHoldSituation update(@RequestBody WarehouseHoldSituation warehouseHoldSituation) {
        warehouseHoldSituationService.updateById(warehouseHoldSituation);
        return warehouseHoldSituation;
    }

    /**
     * 分页查询
     */
    @PostMapping("/page")
    public Page<WarehouseHoldSituation> page(@RequestBody PageQuery<WarehouseHoldSituation> pageQuery) {
        return warehouseHoldSituationService.lambdaQuery().orderByDesc(WarehouseHoldSituation::getBuyTime).page(Page.of(pageQuery.getPageNum(), pageQuery.getPageSize()));
    }


}
